
#include "nst_msg.h"
#include <string.h>
#include "app_msg.h"


/* 静态队列存储区 */
static uint8_t midi_queue_buf[MIDI_MSG_QUEUE_SIZE * sizeof(midi_msg_t)];
static uint8_t uart_rx_queue_buf[UART_RX_MSG_QUEUE_SIZE * sizeof(uart_rx_msg_t)];
static uint8_t uart_tx_queue_buf[UART_PORT_COUNT][UART_TX_MSG_QUEUE_SIZE * sizeof(uart_tx_msg_t)];

/* 队列实例 */
nst_msg_queue_t midi_queue;
nst_msg_queue_t uart_rx_queue;
nst_msg_queue_t uart_tx_queues[UART_PORT_COUNT];

// 初始化 MIDI 和 UART 队列
void app_msg_init(void)
{
    /* 初始化MIDI队列 */
    nst_msg_init(&midi_queue, "MIDI_QUEUE", midi_queue_buf, sizeof(midi_msg_t), MIDI_MSG_QUEUE_SIZE);

    /* 初始化UART接收队列 */
    nst_msg_init(&uart_rx_queue, "UART_RX_QUEUE", uart_rx_queue_buf, sizeof(uart_rx_msg_t), UART_RX_MSG_QUEUE_SIZE);

    /* 初始化3个UART发送队列 */
    for (uint8_t i = 0; i < UART_PORT_COUNT; i++) {
        char name[16];
        snprintf(name, sizeof(name), "UART%d_TX_QUEUE", i+1);
        nst_msg_init(&uart_tx_queues[i], name, uart_tx_queue_buf[i], sizeof(uart_tx_msg_t), UART_TX_MSG_QUEUE_SIZE);
    }
}

// MIDI 队列操作
bool app_msg_enqueue(nst_msg_queue_t *queue, void *msg) 
{
    return nst_msg_enqueue(queue, msg);
}

bool app_msg_dequeue(nst_msg_queue_t *queue, void *msg) 
{
    return nst_msg_dequeue(queue, msg);
}

bool app_msg_is_empty(nst_msg_queue_t *queue) 
{
    return nst_msg_is_empty(queue);
}

bool app_msg_is_full(nst_msg_queue_t *queue) 
{
    return nst_msg_is_full(queue);
}

